<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="物料代码" prop="goodsCode">
        <el-input
          v-model="queryParams.goodsCode"
          placeholder="请输入物料代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="助记码" prop="auxiliaryCode">
        <el-input
          v-model="queryParams.auxiliaryCode"
          placeholder="请输入助记码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规格型号" prop="goodsModel">
        <el-input
          v-model="queryParams.goodsModel"
          placeholder="请输入规格型号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户料号" prop="customerNumber">
        <el-input
          v-model="queryParams.customerNumber"
          placeholder="请输入客户料号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户物料描述" prop="goodsDescription">
        <el-input
          v-model="queryParams.goodsDescription"
          placeholder="请输入客户物料描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料属性" prop="goodsAttr">
        <el-input
          v-model="queryParams.goodsAttr"
          placeholder="请输入物料属性"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计量单位组" prop="unitMeasureGroup">
        <el-input
          v-model="queryParams.unitMeasureGroup"
          placeholder="请输入计量单位组"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基本计量单位" prop="basicUnit">
        <el-input
          v-model="queryParams.basicUnit"
          placeholder="请输入基本计量单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采购计量单位" prop="purchaseUnit">
        <el-input
          v-model="queryParams.purchaseUnit"
          placeholder="请输入采购计量单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售计量单位" prop="saleUnit">
        <el-input
          v-model="queryParams.saleUnit"
          placeholder="请输入销售计量单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产计量单位" prop="productionUnit">
        <el-input
          v-model="queryParams.productionUnit"
          placeholder="请输入生产计量单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库存计量单位" prop="stockUnit">
        <el-input
          v-model="queryParams.stockUnit"
          placeholder="请输入库存计量单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数量精度" prop="quantityPrecision">
        <el-input
          v-model="queryParams.quantityPrecision"
          placeholder="请输入数量精度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="使用状态" prop="usageStatus">
        <el-input
          v-model="queryParams.usageStatus"
          placeholder="请输入使用状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存货科目代码" prop="inventoryCode">
        <el-input
          v-model="queryParams.inventoryCode"
          placeholder="请输入存货科目代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售收入科目代码" prop="revenueCode">
        <el-input
          v-model="queryParams.revenueCode"
          placeholder="请输入销售收入科目代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售成本科目代码" prop="costCode">
        <el-input
          v-model="queryParams.costCode"
          placeholder="请输入销售成本科目代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="税率" prop="taxRate">
        <el-input
          v-model="queryParams.taxRate"
          placeholder="请输入税率"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参与结转式成本还原" prop="costReduction">
        <el-input
          v-model="queryParams.costReduction"
          placeholder="请输入参与结转式成本还原"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划策略" prop="planningStrategy">
        <el-input
          v-model="queryParams.planningStrategy"
          placeholder="请输入计划策略"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划模式" prop="planningMode">
        <el-input
          v-model="queryParams.planningMode"
          placeholder="请输入计划模式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订货策略" prop="orderPolicy">
        <el-input
          v-model="queryParams.orderPolicy"
          placeholder="请输入订货策略"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最小订货量" prop="minOrder">
        <el-input
          v-model="queryParams.minOrder"
          placeholder="请输入最小订货量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最大订货量" prop="maxOrder">
        <el-input
          v-model="queryParams.maxOrder"
          placeholder="请输入最大订货量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="批量增量" prop="batchIncrement">
        <el-input
          v-model="queryParams.batchIncrement"
          placeholder="请输入批量增量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="变动提前期批量" prop="variableBatch">
        <el-input
          v-model="queryParams.variableBatch"
          placeholder="请输入变动提前期批量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="需求时界" prop="demandTime">
        <el-input
          v-model="queryParams.demandTime"
          placeholder="请输入需求时界"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划时界" prop="planningHorizon">
        <el-input
          v-model="queryParams.planningHorizon"
          placeholder="请输入计划时界"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="投料自动取整" prop="autoRounding">
        <el-input
          v-model="queryParams.autoRounding"
          placeholder="请输入投料自动取整"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="MRP计算是否合并需求" prop="calculationMeets">
        <el-input
          v-model="queryParams.calculationMeets"
          placeholder="请输入MRP计算是否合并需求"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否关键件" prop="keyPart">
        <el-input
          v-model="queryParams.keyPart"
          placeholder="请输入是否关键件"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毛重" prop="grossWeight">
        <el-input
          v-model="queryParams.grossWeight"
          placeholder="请输入毛重"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="净重" prop="netWeight">
        <el-input
          v-model="queryParams.netWeight"
          placeholder="请输入净重"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="重量单位" prop="weightUnit">
        <el-input
          v-model="queryParams.weightUnit"
          placeholder="请输入重量单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="长度" prop="length">
        <el-input
          v-model="queryParams.length"
          placeholder="请输入长度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="宽度" prop="width">
        <el-input
          v-model="queryParams.width"
          placeholder="请输入宽度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="高度" prop="height">
        <el-input
          v-model="queryParams.height"
          placeholder="请输入高度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="体积" prop="volume">
        <el-input
          v-model="queryParams.volume"
          placeholder="请输入体积"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位标准工时" prop="standardTime">
        <el-input
          v-model="queryParams.standardTime"
          placeholder="请输入单位标准工时"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="长度精度" prop="lengthAccuracy">
        <el-input
          v-model="queryParams.lengthAccuracy"
          placeholder="请输入长度精度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="体积精度" prop="volumeAccuracy">
        <el-input
          v-model="queryParams.volumeAccuracy"
          placeholder="请输入体积精度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="重量精度" prop="weightAccuracy">
        <el-input
          v-model="queryParams.weightAccuracy"
          placeholder="请输入重量精度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['base:goods:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['base:goods:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['base:goods:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['base:goods:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="goodsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="物料id" align="center" prop="goodsId" /> -->
      <el-table-column label="物料代码" align="center" prop="goodsCode"  width="150px"/>
      <el-table-column label="名称" align="center" prop="name"  width="150px" />
      
      <el-table-column label="规格型号" align="center" prop="goodsModel"   width="300px"/>
      <el-table-column label="客户料号" align="center" prop="customerNumber" />
      <el-table-column label="客户物料描述" align="center" prop="goodsDescription" />
      <el-table-column label="物料属性" align="center" prop="goodsAttr" />
      <el-table-column label="计量单位组" align="center" prop="unitMeasureGroup" />
      <el-table-column label="基本计量单位" align="center" prop="basicUnit" />
      <el-table-column label="采购计量单位" align="center" prop="purchaseUnit" />
      <el-table-column label="销售计量单位" align="center" prop="saleUnit" />
      <el-table-column label="生产计量单位" align="center" prop="productionUnit" />
      <el-table-column label="库存计量单位" align="center" prop="stockUnit" />
      <el-table-column label="数量精度" align="center" prop="quantityPrecision" />
      <el-table-column label="使用状态" align="center" prop="usageStatus" />
      <el-table-column label="存货科目代码" align="center" prop="inventoryCode" />
      <el-table-column label="销售收入科目代码" align="center" prop="revenueCode" />
      <el-table-column label="销售成本科目代码" align="center" prop="costCode" />
      <el-table-column label="税率" align="center" prop="taxRate" />
      <el-table-column label="参与结转式成本还原" align="center" prop="costReduction" />
      <el-table-column label="计划策略" align="center" prop="planningStrategy" />
      <el-table-column label="计划模式" align="center" prop="planningMode" />
      <el-table-column label="订货策略" align="center" prop="orderPolicy" />
      <el-table-column label="最小订货量" align="center" prop="minOrder" />
      <el-table-column label="最大订货量" align="center" prop="maxOrder" />
      <el-table-column label="批量增量" align="center" prop="batchIncrement" />
      <el-table-column label="变动提前期批量" align="center" prop="variableBatch" />
      <el-table-column label="需求时界" align="center" prop="demandTime" />
      <el-table-column label="计划时界" align="center" prop="planningHorizon" />
      <el-table-column label="投料自动取整" align="center" prop="autoRounding" />
      <el-table-column label="MRP计算是否合并需求" align="center" prop="calculationMeets" />
      <el-table-column label="是否关键件" align="center" prop="keyPart" />
      <el-table-column label="毛重" align="center" prop="grossWeight" />
      <el-table-column label="净重" align="center" prop="netWeight" />
      <el-table-column label="重量单位" align="center" prop="weightUnit" />
      <el-table-column label="长度" align="center" prop="length" />
      <el-table-column label="宽度" align="center" prop="width" />
      <el-table-column label="高度" align="center" prop="height" />
      <el-table-column label="体积" align="center" prop="volume" />
      <el-table-column label="单位标准工时" align="center" prop="standardTime" />
      <el-table-column label="长度精度" align="center" prop="lengthAccuracy" />
      <el-table-column label="体积精度" align="center" prop="volumeAccuracy" />
      <el-table-column label="重量精度" align="center" prop="weightAccuracy" />
      <el-table-column label="助记码" align="center" prop="auxiliaryCode" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['base:goods:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['base:goods:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改物料对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="物料代码" prop="goodsCode">
          <el-input v-model="form.goodsCode" placeholder="请输入物料代码" />
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="助记码" prop="auxiliaryCode">
          <el-input v-model="form.auxiliaryCode" placeholder="请输入助记码" />
        </el-form-item>
        <el-form-item label="规格型号" prop="goodsModel">
          <el-input v-model="form.goodsModel" placeholder="请输入规格型号" />
        </el-form-item>
        <el-form-item label="客户料号" prop="customerNumber">
          <el-input v-model="form.customerNumber" placeholder="请输入客户料号" />
        </el-form-item>
        <el-form-item label="客户物料描述" prop="goodsDescription">
          <el-input v-model="form.goodsDescription" placeholder="请输入客户物料描述" />
        </el-form-item>
        <el-form-item label="物料属性" prop="goodsAttr">
          <el-input v-model="form.goodsAttr" placeholder="请输入物料属性" />
        </el-form-item>
        <el-form-item label="计量单位组" prop="unitMeasureGroup">
          <el-input v-model="form.unitMeasureGroup" placeholder="请输入计量单位组" />
        </el-form-item>
        <el-form-item label="基本计量单位" prop="basicUnit">
          <el-input v-model="form.basicUnit" placeholder="请输入基本计量单位" />
        </el-form-item>
        <el-form-item label="采购计量单位" prop="purchaseUnit">
          <el-input v-model="form.purchaseUnit" placeholder="请输入采购计量单位" />
        </el-form-item>
        <el-form-item label="销售计量单位" prop="saleUnit">
          <el-input v-model="form.saleUnit" placeholder="请输入销售计量单位" />
        </el-form-item>
        <el-form-item label="生产计量单位" prop="productionUnit">
          <el-input v-model="form.productionUnit" placeholder="请输入生产计量单位" />
        </el-form-item>
        <el-form-item label="库存计量单位" prop="stockUnit">
          <el-input v-model="form.stockUnit" placeholder="请输入库存计量单位" />
        </el-form-item>
        <el-form-item label="数量精度" prop="quantityPrecision">
          <el-input v-model="form.quantityPrecision" placeholder="请输入数量精度" />
        </el-form-item>
        <el-form-item label="使用状态" prop="usageStatus">
          <el-input v-model="form.usageStatus" placeholder="请输入使用状态" />
        </el-form-item>
        <el-form-item label="存货科目代码" prop="inventoryCode">
          <el-input v-model="form.inventoryCode" placeholder="请输入存货科目代码" />
        </el-form-item>
        <el-form-item label="销售收入科目代码" prop="revenueCode">
          <el-input v-model="form.revenueCode" placeholder="请输入销售收入科目代码" />
        </el-form-item>
        <el-form-item label="销售成本科目代码" prop="costCode">
          <el-input v-model="form.costCode" placeholder="请输入销售成本科目代码" />
        </el-form-item>
        <el-form-item label="税率" prop="taxRate">
          <el-input v-model="form.taxRate" placeholder="请输入税率" />
        </el-form-item>
        <el-form-item label="参与结转式成本还原" prop="costReduction">
          <el-input v-model="form.costReduction" placeholder="请输入参与结转式成本还原" />
        </el-form-item>
        <el-form-item label="计划策略" prop="planningStrategy">
          <el-input v-model="form.planningStrategy" placeholder="请输入计划策略" />
        </el-form-item>
        <el-form-item label="计划模式" prop="planningMode">
          <el-input v-model="form.planningMode" placeholder="请输入计划模式" />
        </el-form-item>
        <el-form-item label="订货策略" prop="orderPolicy">
          <el-input v-model="form.orderPolicy" placeholder="请输入订货策略" />
        </el-form-item>
        <el-form-item label="最小订货量" prop="minOrder">
          <el-input v-model="form.minOrder" placeholder="请输入最小订货量" />
        </el-form-item>
        <el-form-item label="最大订货量" prop="maxOrder">
          <el-input v-model="form.maxOrder" placeholder="请输入最大订货量" />
        </el-form-item>
        <el-form-item label="批量增量" prop="batchIncrement">
          <el-input v-model="form.batchIncrement" placeholder="请输入批量增量" />
        </el-form-item>
        <el-form-item label="变动提前期批量" prop="variableBatch">
          <el-input v-model="form.variableBatch" placeholder="请输入变动提前期批量" />
        </el-form-item>
        <el-form-item label="需求时界" prop="demandTime">
          <el-input v-model="form.demandTime" placeholder="请输入需求时界" />
        </el-form-item>
        <el-form-item label="计划时界" prop="planningHorizon">
          <el-input v-model="form.planningHorizon" placeholder="请输入计划时界" />
        </el-form-item>
        <el-form-item label="投料自动取整" prop="autoRounding">
          <el-input v-model="form.autoRounding" placeholder="请输入投料自动取整" />
        </el-form-item>
        <el-form-item label="MRP计算是否合并需求" prop="calculationMeets">
          <el-input v-model="form.calculationMeets" placeholder="请输入MRP计算是否合并需求" />
        </el-form-item>
        <el-form-item label="是否关键件" prop="keyPart">
          <el-input v-model="form.keyPart" placeholder="请输入是否关键件" />
        </el-form-item>
        <el-form-item label="毛重" prop="grossWeight">
          <el-input v-model="form.grossWeight" placeholder="请输入毛重" />
        </el-form-item>
        <el-form-item label="净重" prop="netWeight">
          <el-input v-model="form.netWeight" placeholder="请输入净重" />
        </el-form-item>
        <el-form-item label="重量单位" prop="weightUnit">
          <el-input v-model="form.weightUnit" placeholder="请输入重量单位" />
        </el-form-item>
        <el-form-item label="长度" prop="length">
          <el-input v-model="form.length" placeholder="请输入长度" />
        </el-form-item>
        <el-form-item label="宽度" prop="width">
          <el-input v-model="form.width" placeholder="请输入宽度" />
        </el-form-item>
        <el-form-item label="高度" prop="height">
          <el-input v-model="form.height" placeholder="请输入高度" />
        </el-form-item>
        <el-form-item label="体积" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入体积" />
        </el-form-item>
        <el-form-item label="单位标准工时" prop="standardTime">
          <el-input v-model="form.standardTime" placeholder="请输入单位标准工时" />
        </el-form-item>
        <el-form-item label="长度精度" prop="lengthAccuracy">
          <el-input v-model="form.lengthAccuracy" placeholder="请输入长度精度" />
        </el-form-item>
        <el-form-item label="体积精度" prop="volumeAccuracy">
          <el-input v-model="form.volumeAccuracy" placeholder="请输入体积精度" />
        </el-form-item>
        <el-form-item label="重量精度" prop="weightAccuracy">
          <el-input v-model="form.weightAccuracy" placeholder="请输入重量精度" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGoods, getGoods, delGoods, addGoods, updateGoods, exportGoods } from "@/api/base/goods";

export default {
  name: "Goods",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料表格数据
      goodsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsCode: undefined,
        name: undefined,
        auxiliaryCode: undefined,
        goodsModel: undefined,
        customerNumber: undefined,
        goodsDescription: undefined,
        goodsAttr: undefined,
        unitMeasureGroup: undefined,
        basicUnit: undefined,
        purchaseUnit: undefined,
        saleUnit: undefined,
        productionUnit: undefined,
        stockUnit: undefined,
        quantityPrecision: undefined,
        usageStatus: undefined,
        inventoryCode: undefined,
        revenueCode: undefined,
        costCode: undefined,
        taxRate: undefined,
        costReduction: undefined,
        planningStrategy: undefined,
        planningMode: undefined,
        orderPolicy: undefined,
        minOrder: undefined,
        maxOrder: undefined,
        batchIncrement: undefined,
        variableBatch: undefined,
        demandTime: undefined,
        planningHorizon: undefined,
        autoRounding: undefined,
        calculationMeets: undefined,
        keyPart: undefined,
        grossWeight: undefined,
        netWeight: undefined,
        weightUnit: undefined,
        length: undefined,
        width: undefined,
        height: undefined,
        volume: undefined,
        standardTime: undefined,
        lengthAccuracy: undefined,
        volumeAccuracy: undefined,
        weightAccuracy: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询物料列表 */
    getList() {
      this.loading = true;
      listGoods(this.queryParams).then(response => {
        this.goodsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        goodsId: undefined,
        goodsCode: undefined,
        name: undefined,
        auxiliaryCode: undefined,
        goodsModel: undefined,
        customerNumber: undefined,
        goodsDescription: undefined,
        goodsAttr: undefined,
        unitMeasureGroup: undefined,
        basicUnit: undefined,
        purchaseUnit: undefined,
        saleUnit: undefined,
        productionUnit: undefined,
        stockUnit: undefined,
        quantityPrecision: undefined,
        usageStatus: undefined,
        inventoryCode: undefined,
        revenueCode: undefined,
        costCode: undefined,
        taxRate: undefined,
        costReduction: undefined,
        planningStrategy: undefined,
        planningMode: undefined,
        orderPolicy: undefined,
        minOrder: undefined,
        maxOrder: undefined,
        batchIncrement: undefined,
        variableBatch: undefined,
        demandTime: undefined,
        planningHorizon: undefined,
        autoRounding: undefined,
        calculationMeets: undefined,
        keyPart: undefined,
        grossWeight: undefined,
        netWeight: undefined,
        weightUnit: undefined,
        length: undefined,
        width: undefined,
        height: undefined,
        volume: undefined,
        standardTime: undefined,
        lengthAccuracy: undefined,
        volumeAccuracy: undefined,
        weightAccuracy: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.goodsId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加物料";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const goodsId = row.goodsId || this.ids
      getGoods(goodsId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改物料";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.goodsId != null) {
            updateGoods(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGoods(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const goodsIds = row.goodsId || this.ids;
      this.$confirm('是否确认删除物料编号为"' + goodsIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delGoods(goodsIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有物料数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportGoods(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
